Some easy (though tiny) speed wins.
Sponsored-by: Luke T. Shumaker on Patreon
import Utility.TimeStamp
import Utility.FileMode
import qualified Utility.RawFilePath as R
+import qualified Utility.FileIO as F
import qualified System.FilePath.ByteString as P
import System.PosixCompat.Files (isSymbolicLink, linkCount)
readContentRetentionTimestamp :: RawFilePath -> Annex (Maybe POSIXTime)
readContentRetentionTimestamp rt =
liftIO $ join <$> tryWhenExists
- (parsePOSIXTime <$> readFile (fromRawFilePath rt))
+ (parsePOSIXTime <$> F.readFile' (toOsPath rt))
{- Checks if the retention timestamp is in the future, if so returns
- Nothing.
import Utility.TimeStamp
import Data.ByteString.Builder
+import qualified Data.ByteString as B
import qualified Data.Attoparsec.ByteString.Lazy as A
currentVectorClock :: Annex CandidateVectorClock
buildVectorClock :: VectorClock -> Builder
buildVectorClock = string7 . formatVectorClock
-parseVectorClock :: String -> Maybe VectorClock
+parseVectorClock :: B.ByteString -> Maybe VectorClock
parseVectorClock t = VectorClock <$> parsePOSIXTime t
vectorClockParser :: A.Parser VectorClock
import Types.VectorClock
import Utility.Env
import Utility.TimeStamp
+import Utility.FileSystemEncoding
startVectorClock :: IO (IO CandidateVectorClock)
startVectorClock = go =<< getEnv "GIT_ANNEX_VECTOR_CLOCK"
where
go Nothing = timebased
- go (Just s) = case parsePOSIXTime s of
+ go (Just s) = case parsePOSIXTime (encodeBS s) of
Just t -> return (pure (CandidateVectorClock t))
Nothing -> timebased
-- Avoid using fractional seconds in the CandidateVectorClock.
where
parse status = foldr parseline status . lines
parseline line status
- | key == "lastRunning" = parseval parsePOSIXTime $ \v ->
+ | key == "lastRunning" = parseval (parsePOSIXTime . encodeBS) $ \v ->
status { lastRunning = Just v }
| key == "scanComplete" = parseval readish $ \v ->
status { scanComplete = v }
| key == "sanityCheckRunning" = parseval readish $ \v ->
status { sanityCheckRunning = v }
- | key == "lastSanityCheck" = parseval parsePOSIXTime $ \v ->
+ | key == "lastSanityCheck" = parseval (parsePOSIXTime . encodeBS) $ \v ->
status { lastSanityCheck = Just v }
| otherwise = status -- unparsable line
where
liftIO $ catchDefaultIO Nothing $ do
timestamp <- modificationTime <$> R.getFileStatus f
let fromstatus = Just (realToFrac timestamp)
- fromfile <- parsePOSIXTime <$> readFile (fromRawFilePath f)
+ fromfile <- parsePOSIXTime <$> F.readFile' (toOsPath f)
return $ if matchingtimestamp fromfile fromstatus
then Just timestamp
else Nothing
mkInodeCache
<$> (readish =<< M.lookup "ino:" m)
<*> (readish =<< M.lookup "size:" m)
- <*> (parsePOSIXTime =<< (replace ":" "." <$> M.lookup "mtime:" m))
+ <*> (parsePOSIXTime =<< (encodeBS . replace ":" "." <$> M.lookup "mtime:" m))
"1" -> Just True
"0" -> Just False
_ -> Nothing
- t <- parsePOSIXTime ts
+ t <- parsePOSIXTime (encodeBS ts)
return (b, t)
bits = splitc ' ' firstline
numbits = length bits
time = if numbits > 0
- then Just <$> parsePOSIXTime =<< headMaybe bits
+ then Just <$> parsePOSIXTime . encodeBS =<< headMaybe bits
else pure Nothing -- not failure
bytes = if numbits > 1
then Just <$> readish =<< headMaybe (drop 1 bits)
, return M.empty
)
where
- parse line = case (readish sint, deserializeKey skey, parsePOSIXTime ts) of
+ parse line = case (readish sint, deserializeKey skey, parsePOSIXTime (encodeBS ts)) of
(Just int, Just key, mtimestamp) -> Just (key, (int, mtimestamp))
_ -> Nothing
where
, return []
)
where
- parse line = case (readish sint, parsePOSIXTime ts) of
+ parse line = case (readish sint, parsePOSIXTime (encodeBS ts)) of
(Just v, Just t) -> Just (RepoVersion v, t)
_ -> Nothing
where
(inode:size:mtime:mtimedecimal:_) -> do
i <- readish inode
sz <- readish size
- t <- parsePOSIXTime $ mtime ++ '.' : mtimedecimal
+ t <- parsePOSIXTime $ encodeBS $ mtime ++ '.' : mtimedecimal
return $ InodeCache $ InodeCachePrim i sz (MTimeHighRes t)
_ -> Nothing
import Data.Ratio
import Control.Applicative
import qualified Data.ByteString as B
-import qualified Data.ByteString.Char8 as B8
import qualified Data.Attoparsec.ByteString as A
import Data.Attoparsec.ByteString.Char8 (char, decimal, signed, isDigit_w8)
A.parseOnly (decimal <* A.endOfInput) b
return (d, len)
-parsePOSIXTime :: String -> Maybe POSIXTime
-parsePOSIXTime s = eitherToMaybe $
- A.parseOnly (parserPOSIXTime <* A.endOfInput) (B8.pack s)
+parsePOSIXTime :: B.ByteString -> Maybe POSIXTime
+parsePOSIXTime b = eitherToMaybe $
+ A.parseOnly (parserPOSIXTime <* A.endOfInput) b
{- This implementation allows for higher precision in a POSIXTime than
- supported by the system's Double, and avoids the complications of
readFile, writeFile, and appendFile on FilePaths.
Note that the FilePath versions do newline translation on windows,
which has to be handled when converting to the Utility.FileIO ones.
+* System.Directory.OsPath is available with OsPath build flag, but
+ not yet used, and would eliminate a lot of fromRawFilePaths.
+ Make Utility.SystemDirectory import it when built with OsPath,
+ and the remaining 6 hours or work will explain itself..
[[!tag confirmed]]